package com.ddd.app.user.executor.query;

import com.ddd.app.user.assembler.UserAssembler;
import com.ddd.client.user.dto.co.UserErrorCode;
import com.ddd.client.user.dto.co.UserCO;
import com.ddd.domain.user.model.entity.UserEntity;
import com.ddd.domain.user.service.UserService;
import com.ddd.infrastructure.common.exception.DddBizException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * 用户信息查询
 *
 * @author guowm
 */
@Component
public class UserInfoQueryExe {
    @Autowired
    private UserService userService;

    public UserCO execute(Long id) {
        UserEntity userEntity = userService.findById(id);
        if (Objects.isNull(userEntity)) {
            throw new DddBizException(UserErrorCode.B_USER_UNDEFINED);
        }

        return UserAssembler.toValueObject(userEntity);
    }
}
